import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreNoticeLogService extends BaseService<any> {
  private readonly logger = new Logger(CoreNoticeLogService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * add
   * 对应 PHP: CoreNoticeLogService_core::add()
   * 逻辑类型: undefined - undefined
   */
  async add(site_id: any[], data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $data['site_id'] = $site_id;         $notice_log = $this->model->create($data);         return $notice_log?->id;     }       public function getPage(i...
data.site_id = site_id;
        const notice_log = this.model.create(data);
        return notice_log?.id;
    }


    async getPage(int site_id, where){
        const field = 'id, site_id, key, notice_type, uid, member_id, nickname, receiver, is_click, is_visit, visit_time, create_time, params, content';
        const search_model = this.model.where([['site_id', '=', site_id))).withSearch(['key','receiver', 'create_time'), where).field(field).order('create_time desc').append(['name', 'notice_type_name')];
        return this.pageQuery(search_model);
    }

    async getInfo(int site_id, int id){
        const field = 'id, site_id, key, notice_type, uid, member_id, nickname, receiver, is_click, is_visit, visit_time, create_time, params, content';
        return this.model.where([['site_id', '=', site_id], ['id', '=', id))).field(field).append(['name', 'notice_type_name')).findOrEmpty().toArray(;
  }
  }

  /**
   * getPage
   * 对应 PHP: CoreNoticeLogService_core::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(site_id: any[], where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $field = 'id, site_id, key, notice_type, uid, member_id, nickname, receiver, is_click, is_visit, visit_time, create_time, params, content';         $s...
const field = 'id, site_id, key, notice_type, uid, member_id, nickname, receiver, is_click, is_visit, visit_time, create_time, params, content';
        const search_model = this.model.where([['site_id', '=', site_id))).withSearch(['key','receiver', 'create_time'), where).field(field).order('create_time desc').append(['name', 'notice_type_name')];
        return this.pageQuery(search_model);
    }

    async getInfo(int site_id, int id){
        const field = 'id, site_id, key, notice_type, uid, member_id, nickname, receiver, is_click, is_visit, visit_time, create_time, params, content';
        return this.model.where([['site_id', '=', site_id], ['id', '=', id))).field(field).append(['name', 'notice_type_name')).findOrEmpty().toArray(;
  }
  }

  /**
   * getInfo
   * 对应 PHP: CoreNoticeLogService_core::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(site_id: number, id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $field = 'id, site_id, key, notice_type, uid, member_id, nickname, receiver, is_click, is_visit, visit_time, create_time, params, content';         re...
const field = 'id, site_id, key, notice_type, uid, member_id, nickname, receiver, is_click, is_visit, visit_time, create_time, params, content';
        return this.model.where([['site_id', '=', site_id], ['id', '=', id))).field(field).append(['name', 'notice_type_name')).findOrEmpty().toArray(;
  }
  }
}
